package com.clouddot.baipai.infrastructure.environment;


import android.app.Activity;
import android.content.Context;

import com.clouddot.baipai.infrastructure.environment.initial.IInitial;
import com.clouddot.baipai.infrastructure.environment.initial.InitialAppContext;
import com.clouddot.baipai.infrastructure.environment.initial.InitialAppUpdate;
import com.clouddot.baipai.infrastructure.environment.initial.InitialHardware;
import com.clouddot.baipai.infrastructure.environment.initial.InitialSaveDataHelper;
import com.clouddot.baipai.model.beam.TargetUrl;
import com.clouddot.baipai.model.netConnect;
import com.clouddot.baipai.presenter.appPresenter;
import com.clouddot.baipai.ui.util.Ftp.FTPUtil;
import com.clouddot.baipai.ui.util.Log.LogUtil;
import com.clouddot.baipai.ui.util.dbHelper.SharedPreferencesHelper;

import java.util.ArrayList;
import java.util.List;

public class Environment
{
	public final static int RUNMODE_DEBUG = 1;
	public final static int RUNMODE_RELEASE = 2;

	private static Environment instance;

	public static Environment getInstance()
	{
		return instance;
	}

	public static Environment createStaticInstance(Context context)
	{
		if (instance == null)
		{
			instance = new Environment(context);
		}
		return instance;
	}

	public int runMode;// 当前运行模式

	public Context context;// 系统上下文

	public appContext appContext;// 软件上下文

	public appPresenter appPresenter;

	public netConnect netConnect;

	private List<IInitial> initials;

	public TargetUrl targetUrl;

	public FTPUtil ftpUtil;

	public com.clouddot.baipai.ui.util.file.fileUtil fileUtil;

	public SharedPreferencesHelper helper;

	public List<Activity> activities;

	public int Height = 0;

	public Environment(Context context)
	{
		this.context = context;
		this.runMode = RUNMODE_RELEASE;// 默认为发布模式
		initials = new ArrayList<IInitial>();
		initials.add(new InitialSaveDataHelper(this));
		initials.add(new InitialHardware(this));
		initials.add(new InitialAppContext(this));
		initials.add(new InitialAppUpdate(this));

		activities = new ArrayList<>();


	}

	public void initial() throws Exception
	{
		for (IInitial initial : initials)
		{
			initial.initial();
		}
	}

	public void initailNoException()
	{
		try
		{
			initial();
		}
		catch (Exception ex)
		{
			LogUtil.e("初始化错误");
		}


	}


	public boolean isDebug()
	{
		return runMode == RUNMODE_DEBUG;
	}

	public boolean isRelease()
	{
		return runMode == RUNMODE_RELEASE;
	}

}
